﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Web.Core;
using Web.Core.Objects;

public partial class include_categorys : System.Web.UI.UserControl
{
    public string categoryName;
    protected void Page_Load(object sender, EventArgs e)
    {
       // this.re
        int total = 10; int page = 1;
        if (Request.Params["page"] != null)
            page = int.Parse(Request.Params["page"]);

        int catID = int.Parse(Request.Params["catid"]);
        this.products.Text = getAllProductByCategory(page, catID, total);
        this.categoryName = Categories.GetCategoryByID(catID,(int)Session["Language"]).Name;

        this.Pager1.objectsPerPage = total;
        this.Pager1.displayAll = true;
        this.Pager1.objectsName = "Sản Phẩm";
        this.Pager1.totalObjects = Products.CountAllProductsByCategoryIDVisible((int)Session["Language"], catID);
    }

    private string getAllProductByCategory(int page,int catID,int total)
    {
        ArrayList list = new ArrayList();
        list = Products.GetAllProductsByCategoryIDVisible((int)Session["Language"], catID, page, total);
        string str = "";
        int i = 0;
        foreach (Product item in list)
        {
            if (i != 3)
            {
                str += "<div style='margin-right: 5px; width: 31%; float: left;'><div style='width: 170px; min-width: 115px;' class='vmBrowseContainer v6BrowseContainer'>";
                str += "<div style='width: px; margin: 2px auto;' class='v6BrowseImageBox'>";
                str += String.Format("<a href='?act=product&id={0}'><img width='170' height='216' border='0' alt='G550' title='{1}' class='browseProductImage' src='images/products/{2}'></a>", item.ProductID,item.Name,item.Image);
                str += " <div class='v6BrowsePriceBox'><span class='productPrice'>$" + item.Price;
                str += "</span><br></div></div><br style='clear: both'><div class='vmBrowseProductTitle v6BrowseProductTitle'>";
                str += String.Format("<a href='?act=product&id={0}'>{1}</a>", item.ProductID, item.Name);
                str += "</div></div></div>";
                i++;
            }
            else
            {
                str += "<br class='clr'>";
                str += "<div style='margin-right: 5px; width: 31%; float: left;'><div style='width: 170px; min-width: 115px;' class='vmBrowseContainer v6BrowseContainer'>";
                str += "<div style='width: px; margin: 2px auto;' class='v6BrowseImageBox'>";
                str += String.Format("<a href='?act=product&id={0}'><img width='170' height='216' border='0' alt='G550' title='{1}' class='browseProductImage' src='images/products/{2}'></a>", item.ProductID, item.Name, item.Image);
                str += " <div class='v6BrowsePriceBox'><span class='productPrice'>" + item.Price;
                str += "</span><br></div></div><br style='clear: both'><div class='vmBrowseProductTitle v6BrowseProductTitle'>";
                str += String.Format("<a href='?act=product&id={0}'>{1}</a>", item.ProductID, item.Name);
                str += "</div></div></div>";
                i = 1;
            }
                           
        }

        return str;
    }



}
